<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>充值</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/common.css"/>
    <link rel="stylesheet" href="../css/main.css"/>
</head>
<body class="recharge">
    <article>
        <section class="container">
            <div class="pt30  bw">
                <p class="plr24">
                    <span class="font17">我要充值</span>
                    <cite class="col9 ml20">余额: <i class="color2" id="money"></i></cite>
                </p>
                <div class="mt30 font16 clearfix money pl24">
                    <label class="color2 item">
                        <input type="radio" name="money" checked hidden class="select" value="50">
                        <div class="selected">50元</div>
                    </label>
                    <label class="color2 item">
                        <input type="radio" name="money" hidden class="select" value="100">
                        <div class="selected">100元</div>
                    </label>
                    <label class="color2 item">
                        <input type="radio" name="money" hidden class="select" value="150">
                        <div class="selected">150元</div>
                    </label>
                    <label class="color2 item">
                        <input type="radio" name="money" hidden class="select" value="200">
                        <div class="selected">200元</div>
                    </label>
                </div>
                <div class="plr24 mt30">
                    <label class="flex_a h100 shadow plr30">
                        <span>其他金额:</span>
                        <input type="number" placeholder="请输入" class="flex1 ml20" id="pay_money">
                    </label>
                </div>
            </div>
            <ul class="bw">
                <li class="pl24">
                    <label class="flex_sb h110">
                        <div class="font0">
                            <img src="../img/ico21.png" style="width: .44rem;">
                            <span class="ml30 font14">微信</span>
                        </div>
                        <div class="flex_a pr24">
                            <input type="radio" name="pay" class="pay" checked>
                            <span class="select flex_aj"></span>
                        </div>
                    </label>
                </li>
            </ul>
            <div class="mt100 plr40">
                <button class="btn_tap bgc1 font16 colw pw100 lh90 border-r6">立即支付</button>
            </div>
        </section>
    </article>
</body>
</html> 
<script src="../js/jquery-1.8.3.min.js"></script>
<script src="../js/dlc.js"></script>
<script>
    var jsApiParameters = null;
    dlc_request('/api/walletDetail/findWallet',{ 'id':get_save('userId')},function(res){
        console.log(res);
        if(res.code == 1){
            $('#money').text('￥'+res.data[0].wallet);
        }else{
            dlctipbox.show(res.msg);
        }
    });
    $('input[name=money]').on('change',function(){
        $('#pay_money').val('');
    });
    $('#pay_money').blur(function(){
        if($(this).val()){
            $('input[name=money]').each(function(){
                $(this).prop('checked',false);
            });
        }
    });
    var onOff = 0;
    $('.btn_tap').click(function(){
        if(onOff == 1)return false;
       if(!$('input[name=money]:checked').val() && !$('#pay_money').val()){
           dlctipbox.show('充值金额不能为空');
       }else{
           var money = $('input[name=money]:checked').val()?$('input[name=money]:checked').val():$('#pay_money').val();
           console.log(money);
           onOff = 1;
           dlc_request('/api/walletDetail/creatRecharge',{ 'userId':get_save('userId')},function(res){
               console.log(res);
               if(res.code == 1){
                   dlc_request('/api/walletDetail/rechargePay',{ 'openId':get_save('openid'),'money':money,'orderNo':res.data},function(res){
                       console.log(res);
                       if(res.code == 1){
                           jsApiParameters = res.data;
                           callpay();
                       }else{
                           onOff = 0;
                           dlctipbox.show(res.msg);
                       }
                   });
               }else{
                   onOff = 0;
                   dlctipbox.show(res.msg);
               }
           });
       }
    });
    function jsApiCall(){
        WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                jsApiParameters,
                function(res){
                    if(res.err_msg == 'get_brand_wcpay_request:ok'){
                        history.go(-1);
                    }else{
                        onOff = 0;
                        dlctipbox.show('支付取消或失败');
                    }
                }
        );
    }
    function callpay(){
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall();
        }
    }
</script>






















